package router

import (
	"common_backend/api/controller"
	"common_backend/common/config"
	_ "common_backend/docs"
	"common_backend/middleware"
	"net/http"

	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func InitRouter() *gin.Engine {
	router := gin.New()
	router.Use(gin.Recovery())
	router.Use(middleware.Cors())
	router.StaticFS(config.Config.ImageSetting.UploadDir, http.Dir(config.Config.ImageSetting.UploadDir))
	router.Use(middleware.Logger())
	register(router)
	return router
}

// 路由注册
func register(router *gin.Engine) {
	router.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	router.GET("/api/captcha", controller.Captcha)
	router.POST("/api/login", controller.Login)
	router.POST("/api/post/add", controller.CreateSysPost)
	router.GET("api/post/page", controller.GetSysPostPage)
	router.GET("api/post/info", controller.GetSysPostById)
	router.PUT("api/post/update", controller.UpdateSysPost)
	router.DELETE("api/post/delete", controller.DeleteSysPostById)
	router.DELETE("/api/post/batchDelete", controller.BatchDeleteSysPost)
	router.PUT("/api/post/updateStatus", controller.UpdateSysPostStatus)
	router.GET("/api/post/vo/list", controller.QuerySysPostVoList)

	router.GET("/api/dept/list", controller.GetSysDeptList)
}
